package bikeAD;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import bikeAD.common_utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import bikeAD.graphql_method;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static io.restassured.RestAssured.given;
import static io.restassured.config.EncoderConfig.encoderConfig;

public class test0003_add_order extends getClassName {

    @Before
    public void before() {
        System.out.println(getClassName()+"开始执行……");
    }

    @After
    public void after() {
        System.out.println(getClassName()+"执行完毕……");
        System.out.println();
    }

    @Test
    public void test_add_order(){
        //获取token
        common_utils common = new common_utils();
        String user_token = common.login_return_token("13066889177");

        //新建一个日期类对象，获取当前的时间戳
        Date nowTime=new Date();
        SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
        String curTime=time.format(nowTime);

        //订单名称
        String order_name = "iphoneX" + curTime;
        System.out.println("order_name = " + order_name);

        //首次投放位置
        String launch_location = "shenzhen";

        //新增订单
        String graphql = "mutation{\n\tadd_sale_order(\n    launch_cycle:3,\n    launch_at:\"2018-12-01\",\n    launch_location:\""+launch_location+"\",\n    ad_form_id:5,\n    ad_amount:1,\n    city_id:23\n    name:\""+order_name+"\",\n    province_id:2\n  ){\n    ad_amount\n    ad_checked_amount\n    ad_form_id\n    ad_form_name\n    ad_id\n    ad_installed_amount\n    city_id\n    city_name\n    created_at\n    godown_at\n    launch_at\n    launch_cycle\n    launch_location\n    mobile\n    name\n    picture_urls\n    province_id\n    province_name\n    sale_order_id\n    sale_order_no\n    sale_order_status\n    updated_at\n    user_id\n    user_name\n  }\n}";
        //System.out.println("新增订单graphql = " + graphql);
        graphql_method method = new graphql_method();
        method.graphql_post_with_token(graphql, user_token);

    }
}
